package com.welink.cmp.dao.metadata;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.welink.cmp.dao.metadata.dataobject.FirewallDO;
import com.welink.cmp.dao.metadata.dataobject.HostDO;
import com.welink.cmp.dto.metadata.firewall.query.FirewallListByPageQry;
import com.welink.cmp.dto.metadata.host.query.HostListByPageQry;
import org.springframework.stereotype.Component;

/**
 * @author yanwei li create  2024-05-19 16:49
 */
@Component
public class FirewallDaoService extends ServiceImpl<BaseMapper<FirewallDO>, FirewallDO> {
    /**
     * 分页查询接口
     *
     * @param pageQry
     * @return
     */
    public Page<FirewallDO> pageQry(FirewallListByPageQry pageQry) {
        Page<FirewallDO> page = new Page<>(pageQry.getPageIndex(), pageQry.getPageSize());
        LambdaQueryWrapper<FirewallDO> wrapper = new LambdaQueryWrapper<>();
        if (pageQry.getName() != null) {
            wrapper.eq(FirewallDO::getName, pageQry.getName());
        }
        if (pageQry.getStrCreateTime() != null) {
            wrapper.ge(FirewallDO::getCreateTime, pageQry.getStrCreateTime());
        }
        if (pageQry.getEndCreateTime() != null) {
            wrapper.le(FirewallDO::getCreateTime, pageQry.getEndCreateTime());
        }
        return this.page(page, wrapper);
    }
}
